package com.link.base.base.accnt.service;

import com.link.base.base.accnt.dao.mybatis.mapper.QdAccountWxMapper;
import com.link.base.base.accnt.model.QdAccountWx;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.dao.siebel.mapper.BasicMapperSiebel;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/7 16:57
 * @version 1.0
 */

@Service
public class QdAccountWxServiceImpl extends BasicServiceImpl<QdAccountWx> implements QdAccountWxService {

    @Resource
    private KeyGenerateService keyGenerateService;
    @Resource
    private QdAccountWxMapper qdAccountWxMapper;

    @Override
    public BasicMapper<QdAccountWx> getBasicMapper() {
        return qdAccountWxMapper;
    }


    @Override
    public BasicMapperSiebel<QdAccountWx> getSiebelBasicMapper() throws Exception {

        return null;
    }

    /**
     * @author HuangLJ
     * @Description 插入更新客户，微信客户的中间表
     * @Date 2017-06-20
     */
    @Override
    public void insert(QdAccountWx qdAccountWx) throws Exception {
        qdAccountWx.setPageFlag(false);
        List list = qdAccountWxMapper.queryByExamplePage(qdAccountWx);
        Long accountId = qdAccountWx.getAccountId();
        String wxAccountId = qdAccountWx.getWxAccountId();
        Long corpId = qdAccountWx.getCorpid();
        boolean flagOne = (list != null && list.size() < 1) ? true : false;
        boolean flagTwo = (null == accountId && null == corpId && null == wxAccountId) ? true : false;
        if (flagOne && !flagTwo) {
            // 如果当前记录总数小于1,则插入记录 否则不做操作
            qdAccountWx.setId(keyGenerateService.keyGenerate());
            qdAccountWxMapper.insertAccountWx(qdAccountWx);
        }
    }

    /**
     * @author HuangLJ
     * @Description 删除客户，微信客户的中间表
     * @Date 2017-06-20
     */
    @Override
    public void deleteQdAccountWx(QdAccountWx qdAccountWx) throws Exception {
        Long corpId = qdAccountWx.getCorpid();
        Long accountId = qdAccountWx.getAccountId();
        String wxAccountId = qdAccountWx.getWxAccountId();
        if (!(null == corpId && "".equals(wxAccountId) && null == accountId)) {
            qdAccountWxMapper.deleteAccountWx(qdAccountWx);
        }
    }

    @Override
    public QdAccountWx queryByAccntIdAndWxAccntId(QdAccountWx qdAccountWx) throws Exception {
        return qdAccountWxMapper.queryByAccntIdAndWxAccntId(qdAccountWx);
    }
}
